import Vue from 'vue'
import App from './App'
import VueI18n from './common/vue-i18n.min.js';


Vue.use(VueI18n)


import store from './store'
import MinCache from './util/MinCache.js'
import tarGetPage from './util/targetPage.js'

Vue.use(MinCache)

import '@/uni_modules/uview-ui/theme.scss';
import "./public.scss";
import "./font.css";
// 引入全局uView
import uView from '@/uni_modules/uview-ui'

import mixin from './common/mixin'

import {
	getByMapsList,
	langDictSerach
} from './api/messages';

const messages = uni.getStorageSync("localDataMaps") | {
	'zh-CN': {},
	'zh-UG': {}
}


const lang = uni.getStorageSync("lang") || 'zh-UG'
uni.setStorageSync("lang", lang)
const i18n = new VueI18n({
	messages: messages,
	locale: lang,
	postTranslation: function(e, e1, e2, e3) {
		var lang = uni.getStorageSync("lang")
		var messages=uni.getStorageSync("localDataMaps")
		var message = messages[lang]
		//console.log(message,"message",e1,message[e1])
		//console.log(e,e1,e==e1,lang)

	 	if (message[e1]==undefined && e == e1 && lang == 'zh-UG' && e!='dir'  && e!='algin') {
		//	console.log("chinese",e1)
			if (uni.$u.test.chinese(e1)) {
				//console.log(e, message[e]==undefined)
				//	console.log("chinese",e1)
				//console.log(e,e1,e2,e3)
				
					langDictSerach(e1)
				
			}
		} 
		return e;
	}
})



Vue.mixin({
	methods: {
		setTabBarIndex(index) {
			if (typeof this.$mp.page.getTabBar === 'function' &&
				this.$mp.page.getTabBar()) {
				this.$mp.page.getTabBar().setData({
					selected: index
				})
			}
		}
	}
})


Vue.prototype.$store = store
Vue.prototype.$targetPage = tarGetPage
Vue.prototype.$loadLanguageMessages = loadLanguageMessages

Vue.config.productionTip = false

App.mpType = 'app'


// #ifdef MP
// 引入uView对小程序分享的mixin封装
const mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js')
Vue.mixin(mpShare)
// #endif

Vue.mixin(mixin)
Vue.prototype._i18n = i18n;

Vue.use(uView)

const app = new Vue({
	i18n,
	store,
	...App
})

uni.hideTabBar()

// 引入请求封装
require('./util/request/index')(app)

app.$mount()
uni.setLocale("zh-UG")

function loadLanguageMessages() {
	//console.log("loadLanguageMessages ")
	getByMapsList().then(res => {
		//	console.log(res)
		for (let var1 in res) {
			//	console.log(var1)
			i18n.setLocaleMessage(var1, res[var1]);
		}
	})
}